home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-09-29 | 3.3 KB | 152 lines | [TEXT/KAHL] |
- #include <stdlib.h>
-
- #if defined( __SC__)
- #include <pascal.h>
- #endif
- #include <Fonts.h>
- #include <Menus.h>
- #include <Packages.h>
- #include <SegLoad.h>
- #include <ToolUtils.h>
- #include <TextEdit.h>
- #include <GestaltEqu.h>
- #include <Memory.h>
- #include <QuickDraw.h>
- #include <Windows.h>
- #include <OSEvents.h>
- #include <Resources.h>
-
- #ifdef do_QT
- #include <Movies.h>
- #endif
- #include "general.h"
- #include "application.h"
-
- application::application( char *resfilename) : general()
- {
- MaxApplZone();
- InitGraf( &(qd.thePort));
- #ifdef _APPL_
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs( 0);
- InitCursor();
- #endif
- FlushEvents( everyEvent, 0);
-
- if( resfilename != 0)
- {
- const short resfileno = OpenResFile( CtoPstr( resfilename));
-
- if( resfileno == -1)
- {
- report_error_and_exit( "application::application: Error opening resource file");
- }
- }
-
- #ifdef do_QT
- InitQuickTime();
- #endif
- #ifndef _APPL_
- //
- // install exit handler to remove windows which are still open:
- //
- #ifdef THINK_CPLUS
- int result = atexit( TryToRecover);
- #else
- int result = atexit( application::TryToRecover);
- #endif
- CheckForError( result, "exit Handler TryToRecover could not be installed.");
- #endif
-
- #ifdef _APPL_
- // MenuHandle applemenu = GetMenu( 128);
- //
- // CheckForError( (applemenu == 0), "GetMenu( 128)");
- // InsertMenu( applemenu, 0); // 0 = beforeid;
- // AddResMenu( applemenu, 'DRVR');
- // DrawMenuBar();
- #endif
- }
-
- #ifndef _APPL_
- #ifdef THINK_CPLUS
- void TryToRecover()
- #else
- void application::TryToRecover()
- #endif
- {
- //
- // This function is called at exit time. It closes all windows
- // belonging to instances of class 'window'. This is done by
- // looking at the WRefCon field. window::window sets this to
- // the constant 'vens' (venster is dutch for window)
- //
- // from SysEqu.h:
- // [GLOBAL VAR] Pointer to first window in window list;
- // 0 if using events but not windows:
- //
- const short WindowList = 0x9D6;
-
- WindowPtr currentwindow = *(WindowPtr *)WindowList;
-
- while( currentwindow)
- {
- const long theID = GetWRefCon( currentwindow);
-
- if( theID == 'vens')
- {
- //
- // we allocated our own WindowRecord => use CloseWindow, not DisposeWindow
- //
- CloseWindow( currentwindow);
- }
- currentwindow = (WindowPtr)(((WindowPeek)currentwindow)->nextWindow);
- }
- InitCursor(); // cursor gets lost occassionally.
- }
- #endif
-
- #ifdef do_QT
- void application::InitQuickTime() const
- {
- long response;
-
- OSErr error = Gestalt( gestaltQuickTime, &response);
-
- CheckForError( error, "gestaltQuickTime");
-
- error = Gestalt( gestaltCompressionMgr, &response);
-
- CheckForError( error, "gestaltCompressionMgr");
-
- error = EnterMovies();
-
- CheckForError( error, "EnterMovies");
- }
- #endif
-
- application::~application()
- {
- #ifdef do_QT
- //
- // TN: QT 510 recommends the following:
- //
- // But, if you’ve nested EnterMovies and ExitMovies calls, this is what we
- // recommend:
- // 1. If you’re writing an application, call EnterMovies and don’t call ExitMovies.
- // This way, any external that uses the same a5 world and calls EnterMovies and
- // ExitMovies will simply increment a counter and then decrement the counter and
- // do nothing else.
- //
- // ExitMovies();
- //
- #endif
- FlushEvents( everyEvent, 0);
- #ifdef _APPL_
- ExitToShell();
- #endif
- }
-